#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: shijianbo
@Email:
@Time: 2022/6/16 15:28
@File: oracle.py
"""

import jaydebeapi

from .basic import DatabaseUtil


# class OracleUtil(DatabaseUtil):
#
#     def __init__(self, user, password, ip, port=1521, **kwargs):
#         self.CURSOR = {}
#         server = kwargs.get('server_name', 'orcl')
#         if user == 'sys':
#             self.db = cx_Oracle.connect(user, password, f'{ip}:{port}/{server}', mode=cx_Oracle.SYSDBA)
#         else:
#             self.db = cx_Oracle.connect(user, password, f'{ip}:{port}/{server}')
#         # self.db.call_timeout=30*1000



class OracleJdbcUtil(DatabaseUtil):

    def __init__(self, user, password, ip, port=3306, **kwargs):
        self.CURSOR = {}
        driver = 'oracle.jdbc.driver.OracleDriver'
        server_name = kwargs.get('server', 'orcl')
        url = f'jdbc:oracle:thin:@//{ip}:{port}/{server_name}'
        jar_ile = kwargs.get("jar_files")
        self.db = jaydebeapi.connect(driver, url, [user, password], jar_ile)
        self.db.jconn.setAutoCommit(False)